#Boa:Dialog:ConsultaCosto

import wx
import consultasBD

def create(parent):
    return ConsultaCosto(parent)

[wxID_CONSULTACOSTO, wxID_CONSULTACOSTOBUTTON1, 
 wxID_CONSULTACOSTOINPRECIOCOSTO, wxID_CONSULTACOSTOINPRECIOLISTA2, 
 wxID_CONSULTACOSTOINPRECIOVENTA, wxID_CONSULTACOSTOINPTC, 
 wxID_CONSULTACOSTOSTATICTEXT1, wxID_CONSULTACOSTOSTATICTEXT2, 
 wxID_CONSULTACOSTOSTATICTEXT3, wxID_CONSULTACOSTOSTATICTEXT4, 
] = [wx.NewId() for _init_ctrls in range(10)]

class ConsultaCosto(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_CONSULTACOSTO, name='ConsultaCosto',
              parent=prnt, pos=wx.Point(273, 150), size=wx.Size(232, 230),
              style=wx.DEFAULT_DIALOG_STYLE, title='Consulta Precios de Costo')
        self.SetClientSize(wx.Size(216, 194))

        self.inptc = wx.TextCtrl(id=wxID_CONSULTACOSTOINPTC, name='inptc',
              parent=self, pos=wx.Point(80, 16), size=wx.Size(100, 21), style=0,
              value='')

        self.staticText1 = wx.StaticText(id=wxID_CONSULTACOSTOSTATICTEXT1,
              label='Cod Sussan:', name='staticText1', parent=self,
              pos=wx.Point(16, 16), size=wx.Size(61, 13), style=0)

        self.staticText2 = wx.StaticText(id=wxID_CONSULTACOSTOSTATICTEXT2,
              label='Precio Lista2:', name='staticText2', parent=self,
              pos=wx.Point(16, 56), size=wx.Size(65, 13), style=0)

        self.inpreciolista2 = wx.TextCtrl(id=wxID_CONSULTACOSTOINPRECIOLISTA2,
              name='inpreciolista2', parent=self, pos=wx.Point(80, 56),
              size=wx.Size(100, 21), style=0, value='')
        self.inpreciolista2.SetEditable(False)

        self.button1 = wx.Button(id=wxID_CONSULTACOSTOBUTTON1,
              label='Consultar', name='button1', parent=self, pos=wx.Point(72,
              160), size=wx.Size(75, 23), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
              id=wxID_CONSULTACOSTOBUTTON1)

        self.staticText3 = wx.StaticText(id=wxID_CONSULTACOSTOSTATICTEXT3,
              label='Precio Costo:', name='staticText3', parent=self,
              pos=wx.Point(16, 96), size=wx.Size(65, 13), style=0)

        self.inpreciocosto = wx.TextCtrl(id=wxID_CONSULTACOSTOINPRECIOCOSTO,
              name='inpreciocosto', parent=self, pos=wx.Point(80, 96),
              size=wx.Size(100, 21), style=0, value='')

        self.staticText4 = wx.StaticText(id=wxID_CONSULTACOSTOSTATICTEXT4,
              label='Precio Venta:', name='staticText4', parent=self,
              pos=wx.Point(16, 128), size=wx.Size(65, 13), style=0)

        self.inprecioventa = wx.TextCtrl(id=wxID_CONSULTACOSTOINPRECIOVENTA,
              name='inprecioventa', parent=self, pos=wx.Point(80, 128),
              size=wx.Size(100, 21), style=0, value='')

    def __init__(self, parent):
        self._init_ctrls(parent)

    def OnButton1Button(self, event):
        self.inpreciocosto.ChangeValue("")
        self.inpreciolista2.ChangeValue("")
        self.inprecioventa.ChangeValue("")
        
        codsussan = self.inptc.GetValue()
        sql = "SELECT * FROM productos where codsussan='%s'" % (codsussan)  
        print sql

        resultados = consultasBD.ordenCrudaDict(sql)        
        for i, r in enumerate(resultados):    
                self.inpreciocosto.ChangeValue(str(r["preciocompra"]))
                self.inpreciolista2.ChangeValue(str(r["preciolt2"]))
                self.inprecioventa.ChangeValue(str(r["preciolt1"]))
    